﻿/*
 * Copyright © 2020, Wuxi Safover Intelligent Technology Co., Ltd. All rights reserved.
 * 
 * 无锡安永智能科技有限公司版权所有，未经许可，不得用于商业用途
 * 
 * Visit: https://www.safover.com/ 
 */

using Safover.LidarCollector.Extensions;

namespace Om.Default
{
    internal abstract class TemperatureBoardPacket : NJOpticalMaserPacket
    {
        public float Temperature
        {
            get
            {
                const int threshold = 3000000;
                const float devidor = 10000f;

                var temp = (RawBytes[8] << 24) | (RawBytes[9] << 16) | (RawBytes[10] << 8) | RawBytes[11];

                var fTemp = (float)(temp > threshold ? -(temp - threshold) / devidor : temp / devidor);

                return fTemp;
            }
        }

        public bool IsOverTemperatureProtection => RawBytes[20].IsBitSet(2);

        public bool IsThermistorConnected => !RawBytes[20].IsBitSet(3);


        public TemperatureBoardPacket(byte[] rawBytes) : base(rawBytes) 
        { }
    }
}
